package com.zcg.blogger.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 正则表达式工具类
 * @author zcg
 *
 */
public class PattemUtil {

	/**
	 * 判断是否是数字
	 * @param str
	 * @return
	 */
	public static boolean number(String str) {
		return matcher(str,"[\\d]+").matches();
	}

	/**
	 * 判断是否为0
	 * @param str
	 * @return
	 */
	public static boolean zero(String str) {
		return matcher(str,"[0]+").matches();
	}

	public static boolean email(String str){
//		return matcher(str,"^([a-zA-Z0-9]+[-|_|\\.]?+[a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$").matches();
		return matcher(
				str,
				"^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$").matches();
	}
	
	/**
	 * 初始化matcher
	 * @param str
	 * @param regex
	 * @return
	 */
	private static Matcher matcher(String str,String regex) {
		Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
		Matcher matcher = pattern.matcher(str);
		return matcher;
	}
}
